package com.mf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mf.entity.Task;
import com.mf.entity.TaskDto;
import com.mf.entity.TaskVo;
import com.mf.exception.CustomExceptionHandler;
import com.mf.mapper.TaskMapper;
import com.mf.service.ITaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 任务 服务实现类
 * </p>
 *
 * @author mf
 * @since 2024-04-13
 */
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService {
    @Resource
    private TaskMapper taskMapper;

    @Override
    public List<Task> findAll(Task task) {
        final LambdaQueryWrapper<Task> queryWrapper = new LambdaQueryWrapper<Task>();
        if(task.getStatus() != null){
            queryWrapper.eq(Task::getStatus, task.getStatus());
        }
        if(task.getType() != null){
            queryWrapper.eq(Task::getType, task.getType());
        }
        if(task.getCycleType() != null){
            queryWrapper.eq(Task::getCycleType, task.getCycleType());
        }

        if(task.getCycleStart() != null){
            queryWrapper.eq(Task::getCycleStart, task.getCycleStart());
        }

        if(task.getCycleEnd() != null){
            queryWrapper.eq(Task::getCycleEnd, task.getCycleEnd());
        }

        if(task.getTName() != null){
            queryWrapper.eq(Task::getTName, task.getTName());
        }
        return taskMapper.selectList(queryWrapper);
    }

    @Override
    public void getByName(String tName) {
        final Task task = taskMapper.getByName(tName);
        System.out.println(task);
        if(null != task){
            throw new CustomExceptionHandler("任务已存在");
        }
    }
}
